Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
How to assign the variables of an array to elements in querySelectorall [Pure Javascript]

I am trying to assign the values of an array to elements that were selected by the querySelectorAll function, Any help is appreciated. The code I am trying to write that when the viewpoint of the browser is below 768px, the text changes to the ones in the array, I have tried all the methods I could think of

var newb = document.querySelectorAll("#buttonsize button")
var arSizes = ["Small", "Medium", "Large", "X-Large", "Large", "XX-Large"]
    for(var i = 0; i < arSizes.length; i++) {
      newb[i].textContent = arSizes[i]
   }

It gives this error

Uncaught TypeError: Cannot set properties of undefined (setting 'textContent')

I also tried doing newb.textContent and also using a forEach function.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think you haven't enough buttons in html so better listing or buttons firstly

var newb = document.querySelectorAll("#buttonsize button");
var arSizes = ["Small", "Medium", "Large", "X-Large", "Large", "XX-Large"];

Array.from(newb).forEach((btnEl, index) => {
  btnEl.textContent = arSizes[index]
});
<div id="buttonsize">
  <button>1</button>
  <button>2</button>
  <button>3</button>
  <button>4</button>
  <button>5</button>
  <button>6</button>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda